package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ViewAppointment;
import com.atguigu.lease.web.app.mapper.ViewAppointmentMapper;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.service.ViewAppointmentService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentItemVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;
    @Autowired
    private ApartmentInfoService apartmentInfoService;
    @Override
    public List<AppointmentItemVo> customselect() {
        return viewAppointmentMapper.customSelectAll();
    }

    @Override
    public AppointmentDetailVo customGetBtId(Long id) {
        ViewAppointment viewAppointment = viewAppointmentMapper.selectById(id);
        if (viewAppointment == null) {
            return null; // 或抛出自定义异常
        }

        // 2. 创建返回的 VO 对象
        AppointmentDetailVo appointmentDetailVo = new AppointmentDetailVo();

        // 3. 复制基础信息到 VO
        BeanUtils.copyProperties(appointmentDetailVo, viewAppointment);

        // 4. 查询关联的公寓信息
        Long apartmentId = viewAppointment.getApartmentId();
        ApartmentDetailVo apartmentDetailVo = apartmentInfoService.customGetById(apartmentId);

        // 5. 设置公寓信息到 VO
        appointmentDetailVo.setApartmentDetailVo(apartmentDetailVo);


        return appointmentDetailVo;
    }
}




